package com.autoloadcache.demo.autoloadcacheDemo.controller;


import com.autoloadcache.demo.autoloadcacheDemo.pojo.User;
import com.autoloadcache.demo.autoloadcacheDemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
public class UserController {

    @Autowired
    private UserService userService;

    // 将查询到的返回值存到redis中
    @RequestMapping("/getUserList")
    public List<User> getUserList(){
        return userService.getUserList();
    }

    // 获取单个用户
    @RequestMapping("/getUserById")
    public User getUserById(@RequestParam(value = "userId")String userId){
        return userService.getUserById(userId);
    }

    @RequestMapping("/getUser1")
    public User getUser1(@RequestParam("userId") int userId){
        return userService.getUser1(userId);
    }

    @PostMapping("/saveUser")
    public void saveUser(@RequestBody User user){
        userService.save(user);
    }

}
